<?php
class enroll extends MY_Controller {
	
	function index(){
		
		$data['title'] = 'GCA Online Enrollment';
		
		$view['content'] = $this->load->view('enrollment-forms/vSelectType', '', TRUE);
		
		$this->load->view('vHead', $data);
		$this->load->view('page-blocks/vBody', $view);
		$this->load->view('page-blocks/vFooter');
		$this->load->view('vFoot');
	}
	
	
	function fill_up_form(){
		
		$type = $this->uri->segment(3);
		if(!isset($type))
			redirect('enroll/');
			
		$type = ucfirst(urldecode($type));
				
		$this->validate_enrollment_form();
			
		
			
		$data['title'] = $type;
		$data['enrollee_type'] = $type;
		$view['content'] = $this->load->view('enrollment-forms/vEnrollee', $data, TRUE);
		
		$this->load->view('vHead', $data);
		$this->load->view('page-blocks/vBody', $view);
		$this->load->view('page-blocks/vFooter');
		$this->load->view('vFoot');
	}
	
	/*======================Select Enrollment Type Post Actions==================================*/
		public function select_enrollment_type(){
			$this->form_validation->set_rules('enrollee_type', '', 'required');
			$this->form_validation->set_message('required', 'Please select your type of enrollment');
			
			if($this->form_validation->run() == FALSE){
				$this->index();
			}
			else {
				
				redirect('enroll/fill_up_form/'.$this->input->post('enrollee_type'));
			}
		}
	/*======================End Select Enrollment Type Post Actions==================================*/	
	
	/*======================= Private Controller Functions======================*/
		private function validate_enrollment_form(){
			$this->form_validation->set_rules('lastname', '', 'required');
			$this->form_validation->set_rules('firstname', '', 'required');
			$this->form_validation->set_message('required', 'Fields with <strong>(*) asterisk</strong>  are required');
			
			if($this->form_validation->run() == FALSE){
				
			}
			else {
				$var = (object) $this->input->post();
				$this->load->model('Enrollee');
				echo $this->Enrollee->add_enrollee($var);
					
			}
		}
		
		
	/*======================= Private Controller Functions======================*/
}
?>